home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / TicOptionsPanel.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  5.5 KB  |  291 lines

  1. /*
  2.  *  Copyright (C) 1993  Robert Davis
  3.  *
  4.  *  This program is free software; you can redistribute it and/or
  5.  *  modify it under the terms of Version 2, or any later version, of 
  6.  *  the GNU General Public License as published by the Free Software 
  7.  *  Foundation.
  8.  */
  9.  
  10.  
  11. static char RCSId[]="$Id: TicOptionsPanel.m,v 1.13 1993/05/29 04:32:56 davis Exp $";
  12.  
  13.  
  14. #import <appkit/Application.h>
  15. #import <appkit/Button.h>
  16. #import <appkit/MenuCell.h>
  17. #import <appkit/PopUpList.h>
  18. #import <appkit/Matrix.h>
  19.  
  20. #import "AutoTicsPane.h"
  21. #import "Gnuplot.h"
  22. #import "GnuplotPlot.h"
  23. #import "SeriesTicsPane.h"
  24. #import "Status.h"
  25. #import "StatusTics.h"
  26. #import "TicOptionsPanel.h"
  27. #import    "UserTicsPane.h"
  28.  
  29. @interface TicOptionsPanel (Private)
  30. - _setupPane:(Pane *)aPane;
  31. - _selectPane:(int)aPane;
  32. - _swapPane:(Pane *)new;
  33. - _updatePanel;            /** Overridden from OptionsPanel (Private) **/
  34. @end
  35.  
  36.  
  37. @implementation TicOptionsPanel
  38.  
  39. - init
  40. {
  41.     [super init];
  42.  
  43.     [NXApp loadNibSection: "TicOptionsPanel.nib"
  44.             owner: self
  45.         withNames: NO
  46.          fromZone: [self zone]];
  47.  
  48.     [panel setFrameUsingName:"TicOptionsPanel"];
  49.     [panel setFrameAutosaveName:"TicOptionsPanel"];
  50.  
  51.     return self;
  52. }
  53.  
  54.  
  55. - free
  56. {
  57.     [seriesPane free];
  58.     [userPane free];
  59.     [autoPane free];
  60.     [[coordButton target] free];
  61.  
  62.     return [super free];
  63. }
  64.  
  65.  
  66. - changeCoord:sender
  67. {
  68.     [coordButton setTag:[sender selectedTag]];
  69.     [self _updatePanel];
  70.     return self;
  71. }
  72.  
  73.  
  74. - (int)coord
  75. {
  76.     PopUpList    *popUp = [coordButton target];
  77.     Matrix    *matrix = [popUp itemList];
  78.     int        tag = [[matrix selectedCell] tag];
  79.  
  80.     return tag;
  81. }
  82.  
  83.  
  84. - doSetTicsType:sender
  85. {
  86.     int        tag = [sender selectedTag];
  87.  
  88.     [status setTicTypeCoord:[[coordButton target] indexOfItem:
  89.                  [coordButton title]] to:tag];
  90.     [typeButton setTag:tag];
  91.     [self _updatePanel];
  92.     return self;
  93. }
  94.  
  95.  
  96.  
  97. /*  
  98.  *  Overridden because the superclass (OptionsPanel) only checks to 
  99.  *  see if the current status has changed -- we need to know if the 3D 
  100.  *  state of the doc has changed, too.
  101.  */
  102. - windowDidUpdate:sender
  103. {
  104.     static BOOL    wasThreeD = NO;
  105.     id        mainWindow = [NXApp mainWindow];
  106.     Status    *newStatus;
  107.     BOOL    newThreeD = wasThreeD;
  108.  
  109.     if (mainWindow)
  110.     newStatus = [[mainWindow delegate] status];
  111.     else {
  112.     id    doc;
  113.     if (doc = [[NXApp delegate] currentDoc])
  114.         newStatus = [doc status];
  115.     else
  116.         newStatus = nil;
  117.     }
  118.  
  119.     /*  
  120.      *  Update if the current status object is different or if the 3D 
  121.      *  status has changed (so we can enable/disable the third choice 
  122.      *  in the pop up list).
  123.      */
  124.  
  125.     newThreeD = newStatus? [newStatus isThreeD] : wasThreeD;
  126.     if ((newStatus != status) || (newThreeD != wasThreeD)) {
  127.     status = newStatus;
  128.     [self _updatePanel];
  129.     }
  130.  
  131.     wasThreeD = newThreeD;
  132.     return self;
  133. }
  134.  
  135.  
  136. // Shuts up the compiler about unused RCSId
  137. - (const char *) rcsid
  138. {
  139.     return RCSId;
  140. }
  141.  
  142.  
  143. @end
  144.  
  145.  
  146.  
  147.  
  148.  
  149. @implementation TicOptionsPanel (Private)
  150.  
  151. - _setupPane:(Pane *)aPane
  152. {
  153.     if (aPane) {
  154.     View    *panesView = [aPane view];
  155.  
  156.     [[panel contentView] addSubview: panesView];
  157.     [[panesView allocateGState] lockFocus];
  158.     [panesView unlockFocus];
  159.     [panesView moveTo:0:0];
  160.     }
  161.  
  162.     return self;
  163. }
  164.  
  165.  
  166. - _selectPane:(int)aPane
  167. {
  168.     switch (aPane) {
  169.  
  170.     case TIC_SERIES:
  171.     if (!seriesPane) {
  172.         seriesPane = [[SeriesTicsPane allocFromZone:[self zone]] init];
  173.         [self _setupPane:seriesPane];
  174.     }
  175.     [self _swapPane:seriesPane];
  176.     break;
  177.  
  178.     case TIC_USER:
  179.     if (!userPane) {
  180.         userPane = [[UserTicsPane allocFromZone:[self zone]] init];
  181.         [self _setupPane:userPane];
  182.     }
  183.     [self _swapPane:userPane];
  184.     break;
  185.  
  186.     default:
  187.     if (!autoPane) {
  188.         autoPane = [[AutoTicsPane allocFromZone:[self zone]] init];
  189.         [self _setupPane:autoPane];
  190.     }
  191.     [self _swapPane:autoPane];
  192.     break;
  193.  
  194.     }
  195.  
  196.     [currentPane perform:@selector(selectControl:)
  197.             with:self
  198.           afterDelay:1
  199.       cancelPrevious:YES];
  200.  
  201.     return self;
  202. }
  203.  
  204.  
  205. - _swapPane:(Pane *)new
  206. {
  207.     /*
  208.      *  If the new pane is not already visible, move it into the panel.
  209.      */
  210.  
  211.     if (new != currentPane) {
  212.  
  213.     [[panel contentView] replaceSubview:[currentPane view]
  214.                        with:[new view]];
  215.     [currentPane didSwapOut:self];
  216.  
  217.     /*
  218.      *  Notice we send ourself as the doc so that the pane can
  219.      *  query us for such things as the current coordinate.
  220.      */
  221.     [[new didSwapIn:self] updateStatus:status doc:self];
  222.  
  223.     [panel setTitle:[new title]];
  224.     [panel setMiniwindowIcon:[new icon]];
  225.  
  226.     currentPane = new;
  227.  
  228.     }
  229.  
  230.     return self;
  231. }
  232.  
  233.  
  234.  
  235.  
  236. - _updatePanel
  237. {
  238.     int        coord = [coordButton tag];
  239.     int        type = [typeButton tag];
  240.     BOOL    isEnabled;
  241.  
  242.     [panel disableDisplay];
  243.  
  244.     /*
  245.      *  If the current status is not nil, update the values of all the
  246.      *  controls.
  247.      */
  248.     if (status) {
  249.  
  250.     MenuCell    *cell;
  251.     BOOL        isThreeD = [status isThreeD];
  252.  
  253.     if (!isThreeD && (coord == Z_TAG))  {
  254.         cell = [[coordButton target] findCellWithTag:X_TAG];
  255.         [coordButton setTitle:[cell title]];
  256.         [coordButton setTag:coord = [cell tag]];
  257.     }
  258.  
  259.     type = [status ticTypeCoord:coord];
  260.     cell = [[typeButton target] findCellWithTag:type];
  261.     [typeButton setTitle:[cell title]];
  262.     [typeButton setTag:type];
  263.  
  264.     /*
  265.      *  Enabling/Disabling of the Z coordinate button in the pop
  266.      *  up list.
  267.      */
  268.     
  269.     [[[coordButton target] findCellWithTag:Z_TAG] setEnabled:isThreeD];
  270.  
  271.     }
  272.  
  273.     /* Enable/disable our controls */
  274.  
  275.     [coordButton setEnabled: isEnabled = (status? YES : NO)];
  276.     [coordLabelField setEnabled: isEnabled];
  277.     [typeButton setEnabled: isEnabled];
  278.     [typeLabelField setEnabled: isEnabled];
  279.  
  280.     [self _selectPane:type];
  281.     [currentPane updateStatus:status doc:self];
  282.  
  283.     [panel reenableDisplay];
  284.     [panel display];
  285.  
  286.     return self;
  287. }
  288.  
  289.  
  290. @end
  291.